Skip to content

[TrimmableTypeMap] Inline activation ctor in UCO wrappers#11089

Closed
simonrozsival wants to merge 1 commit intodev/simonrozsival/fix-uco-activation-parityfrom
dev/simonrozsival/trimmable-uco-inline
Closed

[TrimmableTypeMap] Inline activation ctor in UCO wrappers#11089
simonrozsival wants to merge 1 commit intodev/simonrozsival/fix-uco-activation-parityfrom
dev/simonrozsival/trimmable-uco-inline

Conversation

@simonrozsival
Copy link
Copy Markdown
Member

@simonrozsival simonrozsival commented Apr 8, 2026

Inline UCO activation

Depends on: #11094 (WithinNewObjectScope guard)

Scope

  • remove TrimmableTypeMap.ActivateInstance() from the runtime path
  • inline activation directly in generated nctor_*_uco wrappers
  • keep the generated, non-reflective activation flow for both leaf and inherited activation ctors
  • keep the small PEAssemblyBuilder.EmitBody(..., useBranches: true) plumbing needed by the emitted IL
  • keep the no-op open-generic UCO registration behavior needed for valid generated wrappers

Not in this PR

Generated IL shape

[UnmanagedCallersOnly]
static void nctor_0_uco(IntPtr jnienv, IntPtr self)
{
    if (JniEnvironment.WithinNewObjectScope)
        return;

    var obj = (MyActivity)RuntimeHelpers.GetUninitializedObject(typeof(MyActivity));
    obj.BaseCtor(self, JniHandleOwnership.DoNotTransfer);
}

- UCO constructors directly call activation ctor (no ActivateInstance indirection)
- WithinNewObjectScope guard prevents double peer creation
- No-op UCO for open generic type definitions
- ControlFlowBuilder support in PEAssemblyBuilder
- Remove TrimmableNativeRegistration wrapper and ActivateInstance

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@simonrozsival simonrozsival force-pushed the dev/simonrozsival/trimmable-uco-inline branch from b676200 to c19872c Compare April 9, 2026 15:58
@simonrozsival simonrozsival changed the base branch from dev/simonrozsival/trimmable-generator-fixes to dev/simonrozsival/fix-uco-activation-parity April 9, 2026 15:58
@simonrozsival
Copy link
Copy Markdown
Member Author

Folded into #11094 so the guard and inline-activation changes are reviewed together in one PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

copilot `copilot-cli` or other AIs were used to author this trimmable-type-map

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant